<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" style="margin:6px 0" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item class="qryItem" style="margin-left:-28px" label="项目">
          <el-input v-model="queryParam.qry_str" placeholder="项目名称"></el-input>
        </el-form-item>
        <el-form-item class="qryItem" label="项目编号">
          <el-input v-model="queryParam.qry_projectcode" placeholder="项目编号"></el-input>
        </el-form-item>
        <el-form-item class="qryItem" label="单据状态">
          <el-select v-model="queryParam.qry_state" clearable>
            <el-option v-for="item in codeModel.stateList" :key="item.code" :label="item.name" :value="item.code" clearable />
          </el-select>
        </el-form-item>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar class="tl-list-toolbar" ref="toolbar" :refMainTable="$refs.mainTable" currentModuleTableCode="mpmProjectReview/main" :startColumn="3" :isDisplayAdd="false" :isDisplayExport="false" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="false" :isDisplayDeleteBatch="false">
      <template slot="left-btn"> </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
            >项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="projectname" label="项目名称" min-width="300px" sortable="custom" sort-by="projectname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectcode" label="项目编号" width="150px" sortable="custom" sort-by="reviewcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
<!--        <el-table-column prop="dispendtype" label="结项类型" width="150px" sortable="custom" sort-by="endtype" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>-->
        <el-table-column prop="dispprojectresult" label="项目结果" width="150px"  align="center" header-align="center" :show-overflow-tooltip="true">
          <template v-slot="scope">
            <span v-if="scope.row.dispprojectresult">{{scope.row.dispprojectresult}}</span>
            <span v-else>{{scope.row.dispendtype}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="settlementmoney" label="结项金额(万元)" width="120px" sortable="custom"  sort-by="settlementmoney" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="actualresult" label="项目成果" width="150px" sortable="custom" sort-by="achievements" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectdescription" label="结项说明" width="150px" sortable="custom" sort-by="projectdescription" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="applydeptname" label="申请部门" width="250px" sortable="custom" sort-by="applydeptname" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="applyusername" label="申请人姓名" width="120px" sortable="custom" sort-by="applyusername" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="applyusercode" label="申请人工号" width="120px" sortable="custom" sort-by="applyusercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="submitdate" label="提交日期" width="120px" sortable="custom" sort-by="submitdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispstate" label="状态" width="100px" sortable="custom" sort-by="state" align="center" header-align="center" :show-overflow-tooltip="true">
          <template v-slot="scope">
            <el-tag :type="changeStateType(scope.row.state)">
              {{ scope.row.dispstate }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="latestphase" label="最新阶段" width="120px" sortable="custom" sort-by="latestphase" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-view" @click.native="openReviewViewDialog(scope.row)">查看 </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
      <tl-edit-new ref="editFormNew" :projectinfo="projectinfo" @refresh="doRefresh"></tl-edit-new>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
import tlEditNew from './editnew'

/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'mpmProjectReview',
  mixins: [mixin_list],
  components: { tlEdit, tlEditNew },
  data() {
    return {
      description: '项目复盘结项-列表查询',
      urlPrefix: '/mpm/projectReview/',
      url: {
        queryCodeList: '/mpm/projectReview/dataCodeList'
      },
      reduceHeight: 264,
      // 排序参数
      sorterInfo: {
        sidx: 'sortcode',
        sord: 'asc'
      },
      queryParam: {
        qry_projectcode: this.projectinfo.projectcode
      }
    }
  },
  props: {
    projectinfo: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  methods: {
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    },
    beforeLoadData() {
      this.queryParam.qry_usercode = 1
      return true
    },
    /** 改变审核状态标签颜色 */
    changeStateType(state) {
      return state === 0 ? 'info' : state === 2 ? 'danger' : state === 9 ? 'success' : ''
    },
    openReviewViewDialog(row) {
      // 新数据打开新页面(reviewflag为0或为开立、退回状态单据)
      row.reviewflag === 0 || row.state === 0 || row.state === 2 ? this.openViewDialog('editFormNew', row[this.$refs.mainTable.rowKey]) : this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
    },
    doRowDbClick(row) {
      // 新数据打开新页面(reviewflag为0或为开立、退回状态单据)
      row.reviewflag === 0 || row.state === 0 || row.state === 2 ? this.openViewDialog('editFormNew', row[this.$refs.mainTable.rowKey]) : this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
    }
  }
}
</script>

<style scoped>
.app-container {
  margin: 0;
}
</style>
